import 'package:flutter/material.dart';
import 'package:catcher/catcher_plugin.dart';
import 'application.dart';
import 'utils/api.dart';
import 'config.dart';
import 'pages/index.dart';

void main() {
  CatcherOptions debugOptions =
      CatcherOptions(DialogReportMode(), [ConsoleHandler()]);
  CatcherOptions releaseOptions = CatcherOptions(DialogReportMode(), [
    EmailManualHandler(["shirne@126.com"])
  ]);

  Catcher(ShirneApp(), debugConfig: debugOptions, releaseConfig: releaseOptions);
}

class ShirneApp extends StatefulWidget {
  @override
  State<ShirneApp> createState() => _ShirneAppState();
}

class _ShirneAppState extends State<ShirneApp> {
  MaterialColor mColor = Colors.blue;
  bool initialized = false;

  @override
  void initState() {
    super.initState();

    _init();
  }

  _init() async {
    print(context);
    await Config.init(context);
    await Api.init();
    await Application.init();

    setState(() {
      initialized = true;
    });
  }

  @override
  Widget build(BuildContext context) {
    return initialized
        ? MaterialApp(
            title: '临风小筑',
            theme: ThemeData(
              primarySwatch: mColor,
            ),
            home: IndexPage(),
            routes: Application.routes,
          )
        : Container(
            color: Colors.blueAccent,
            child: Center(
              child: CircularProgressIndicator(),
            ),
          );
  }
}
